import request from '@/utils/request'

export const roleApi = {
  // 创建角色
  createRole: (role) => {
    return request.post('/api/roles', role)
  },

  // 获取角色详情
  getRole: (id) => {
    return request.get(`/api/roles/${id}`)
  },

  // 更新角色
  updateRole: (id, role) => {
    return request.put(`/api/roles/${id}`, role)
  },

  // 删除角色
  deleteRole: (id) => {
    return request.delete(`/api/roles/${id}`)
  },

  // 获取角色列表
  getRoles: (page = 1, size = 10) => {
    return request.get('/api/roles', {
      params: { page, size }
    })
  },

  // 获取角色的用户列表
  getRoleUsers: (roleId, page = 1, size = 10) => {
    return request.get(`/api/roles/${roleId}/users`, {
      params: { page, size }
    })
  },

  // 为角色分配用户
  assignUser: (roleId, userId) => {
    return request.post(`/api/roles/${roleId}/users`, {
      roleId,
      userId
    })
  },

  // 移除角色用户
  removeUser: (roleId, userId) => {
    return request.delete(`/api/roles/${roleId}/users/${userId}`)
  }
} 